package com.ym.b2b.brand.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ym.b2b.brand.dao.EmBBrandDAO;
import com.ym.b2b.brand.service.EmBBrandService;
import com.ym.b2b.brand.sqlbean.EmBBrand;
import com.ym.b2b.commons.conf.B2BConstants;
import com.ym.b2b.commons.conf.WebTokenUser;
import com.ym.b2b.commons.controller.BaseController;
import com.zc.commons.base.Page;
import com.zc.commons.base.Result;

/***
 * @ClassName: ManagerEmBBrandContorller
 * @Description: 品牌 后台处理
 * @Author tangxiaojuan
 * @Date 2015年3月6日 下午4:05:13
 * @Modify
 * @CopyRight 珍诚医药在线股份有限公司
 */
@Controller
@RequestMapping("/brand")
public class EmBBrandContorller extends BaseController {

    @Autowired
    private EmBBrandService emBBrandService;
    @Autowired
    private EmBBrandDAO     emBBrandDao;

    @RequestMapping("showBrandDetail.s")
    public ModelAndView showEmBBrandDetail(EmBBrand emBBrand, HttpServletRequest req) {
        ModelAndView m = new ModelAndView();
        Result ret = new Result();
        try {
            ret = emBBrandService.showEmBBrandDetail(emBBrand);
        } catch (Exception e) {
            ret.setCodeResult(Result.CODE_100, e.getMessage());
        }
        m.setViewName("brand/brand_detail_d");
        m.addObject("emBBrand", ret.getData("emBBrand"));
        return m;
    }

    @RequestMapping(value = "showBrandIndex.s")
    public ModelAndView showBrandIndex(EmBBrand emBBrand, Page<EmBBrand> page, HttpServletRequest req) {
        ModelAndView m = new ModelAndView();
        try {
            WebTokenUser tokenUser = getWebTokenUser(req);
            if (tokenUser != null) {
                emBBrand.setUser(tokenUser);
            }
            page.setPageable("true");
            page.setPageSize(5);
            page.setPageUrl(req);
            Result result = new Result();
            emBBrand.setIsShow(1);
            result = emBBrandService.searchPageEmBBrand(page, emBBrand);
            m.addObject("ret", result);
            m.setViewName("brand/index_d");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            m.addObject("msg", e.getMessage());
            m.setViewName(B2BConstants.WEB_ERROR);
        }
        return m;
    }

}
